<?php
namespace Org\Util;

class PDOFactory{
	
	public static function GetPDO($host,$dbname,$user,$pass){
		$strKey=md5(serialize(array($host,$dbname,$user,$pass)));
		if(!isset($GLOBALS[$strKey])){
			$GLOBALS[$strKey]=new \PDO("mysql:host=".$host.";dbname=".$dbname,$user,$pass);
		}
		return $GLOBALS[$strKey];
	}
}

class Mysql{
	protected $mysql;
	
	function __construct(){
		
		$host	=	C('db_host');
		$dbName	=	C('db_name');
		$user	=	C('db_user');
		$pass	=	C('db_pass');
		
		$this->mysql=PDOFactory::GetPDO($host,$dbName,$user,$pass);
		if(!$this->mysql) echo "mysql connect is faild!<br>";
		$this->mysql->query("set names utf8");
	}
	
	function __destruct(){
		$this->mysql=NULL;
	}
}
?>